{$CLEO .cs}
{$USE CLEO+}
{$USE newOpcodes}
{$USE ini}

0000: NOP

script_name "The holster on the cops"

// By ArtemQa146

const
    cops_belt = 24@
    cops_render = 17@
    cops_render_bat = 10@
    cops_change = 31@
    holster_model = 9@
    find = 8@
    cops_find = 0@

    Pistol_X = -0.156
    Pistol_Y = 0.0
    Pistol_Z = 0.09
    Rotate_X = 260.0
    Rotate_Y = 0.0
    Rotate_Z = 0.0
    
    Bat_X = -0.042
    Bat_Y = 0.09
    Bat_Z = -0.085
    Bat_Rotate_X = 280.0
    Bat_Rotate_Y = 100.0
    Bat_Rotate_Z = 0.0
end

if
    0E2D: is_game_first_start
then
    0F00: load_special_model_dff "ModelsQa\Holster" txd "ModelsQa\Holster" store_to 0@
    0AF1: write_int 0@ to_ini_file "cleo\Holster Model.ini" section "Models" key "Holster"
end

cops_change = 0

0AF0: holster_model = read_int_from_ini_file "cleo\Holster Model.ini" section "Models" key "Holster"

while true
wait 0
    if
        player.Defined(0)
    then
    
        //   
        for cops_change = 0 to 6 step 1
            if
                056D: actor cops_belt(cops_change,1i) defined
            then
                //   45
                04B8: get_weapon_data_from_actor cops_belt(cops_change,1i) slot 3 weapon 2@ ammo 1@ model 1@ // 3 - , 4 , 5 
                if
                    02D8:   actor cops_belt(cops_change,1i) current_weapon == 2@
                then
                    0E31: set_render_object_visible cops_render(cops_change,1i) 0
                else
                    if
                        0491:   actor cops_belt(cops_change,1i) has_weapon 2@
                    then
                        0E31: set_render_object_visible cops_render(cops_change,1i) 1
                    end
                end
                
                //   
                04B8: get_weapon_data_from_actor cops_belt(cops_change,1i) slot 2 weapon 2@ ammo 1@ model 1@ // 3 - , 4 , 5 
                if
                    02D8:   actor cops_belt(cops_change,1i) current_weapon == 2@
                then
                    0E31: set_render_object_visible cops_render_bat(cops_change,1i) 0
                else
                    if
                        0491:   actor cops_belt(cops_change,1i) has_weapon 2@
                    then
                        0E31: set_render_object_visible cops_render_bat(cops_change,1i) 1
                    end
                end
                
                if
                    0118:   actor cops_belt(cops_change,1i) dead
                then
                    0E31: set_render_object_visible cops_render_bat(cops_change,1i) 0
                    0E31: set_render_object_visible cops_render(cops_change,1i) 0
                    cops_belt(cops_change,1i) = -1 //     
                end
                
            else
                cops_belt(cops_change,1i) = -1 //     
            end
        end

        //  
        find = 0
        while get_any_char_no_save_recursive find progress_to find char_to cops_find
        089F: get_actor cops_find pedtype_to 1@
            if and
                0EE4: locate_char_distance_to_char $player_actor char cops_find radius 50.0
                1@ == 6 // 
                8118:   not actor cops_find dead
            then
            
                //        
                if or
                    003B:   cops_find == 24@  // (int)
                    003B:   cops_find == 25@  // (int)
                    003B:   cops_find == 26@  // (int)
                    003B:   cops_find == 27@  // (int)
                    003B:   cops_find == 28@  // (int)
                    003B:   cops_find == 29@  // (int)
                    003B:   cops_find == 30@  // (int)
                then
                    continue
                end
            
                //        
                for cops_change = 0 to 6 step 1
                    if and
                        056D: actor cops_find defined
                        856D: not actor cops_belt(cops_change,1i) defined
                    then
                    
                        04B8: get_weapon_data_from_actor cops_find slot 3 weapon 1@ ammo 1@ model 2@ // 3 - , 4 , 5 
                        04B8: get_weapon_data_from_actor cops_find slot 2 weapon 1@ ammo 1@ model 3@ // 3 - , 4 , 5 
                        //      
                        if and
                            2@ > 0
                            3@ > 0
                        then
                            0085: cops_belt(cops_change,1i) = cops_find //    
                            model.Load(2@)
                            model.Load(3@)
                            038B: load_requested_models
                            0E2E: create_render_object_to_char_bone cops_belt(cops_change,1i) model 2@ bone 51 offset Pistol_X Pistol_Y Pistol_Z rotation Rotate_X Rotate_Y Rotate_Z store_to cops_render(cops_change,1i)
                            0F02: create_render_object_to_char_bone_from_special cops_belt(cops_change,1i) special_model holster_model bone 51 offset Pistol_X Pistol_Y Pistol_Z rotation Rotate_X Rotate_Y Rotate_Z store_to 1@
                            0E2E: create_render_object_to_char_bone cops_belt(cops_change,1i) model 3@ bone 41 offset Bat_X Bat_Y Bat_Z rotation Bat_Rotate_X Bat_Rotate_Y Bat_Rotate_Z store_to cops_render_bat(cops_change,1i)
                            model.Destroy(3@)
                            model.Destroy(2@)
                        end
                        
                        break
                    end
                end
                
            end
        end
    end
end